package businesslogic.frameworkBl;

import java.rmi.Naming;

import po.frameworkPO.FrameworkPO;
import vo.frameworkVO.FrameworkVO;
import businesslogicservice.frameworkblservice.FrameworkBLService;
import dataservice.ResultMessage;
import dataservice.frameworkDataService.FrameworkDatabaseService;

public class Framework implements FrameworkBLService {
	private static final String ADDRESS_STRING="localhost";

/*	
 * 更新框架策略
 */
	@Override
	public ResultMessage update(FrameworkVO frameworkVO) throws Exception{
		ResultMessage resultMessage = null;
		FrameworkPO frameworkPO = new FrameworkPO(
				frameworkVO.getCompulsoryLow(),
				frameworkVO.getCompulsoryHigh(), frameworkVO.getChooseLow(),
				frameworkVO.getChooseHigh(), frameworkVO.getCoreLow(),
				frameworkVO.getCoreHigh());
		try {
			FrameworkDatabaseService f = (FrameworkDatabaseService) Naming
					.lookup("rmi://"+ADDRESS_STRING+":8888/frameworkData");
			resultMessage = f.update(frameworkPO);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		return resultMessage;
	}

/*	
 * 得到框架策略
 */
	@Override
	public FrameworkVO find() throws Exception{
		FrameworkVO frameworkVO = null;
		try {
			FrameworkDatabaseService f = (FrameworkDatabaseService) Naming
					.lookup("rmi://"+ADDRESS_STRING+":8888/frameworkData");
			FrameworkPO frameworkPO = f.find();
			frameworkVO = new FrameworkVO(frameworkPO.getCompulsoryLow(),
					frameworkPO.getCompulsoryHigh(),
					frameworkPO.getChooseLow(), frameworkPO.getChooseHigh(),
					frameworkPO.getCoreLow(), frameworkPO.getCoreHigh());

		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		return frameworkVO;
	}

}